const {imgUrl} = getApp().globalData
import { mineApi } from "../../../utils/request/api/mine";

Page({
  data: {
    imgUrl: imgUrl + 'mine/',
    active: 0,
    zb: 0,
    refresherStatus: false,
    hasMore: true,
    page: 1,
    page_size: 10,
    total: 0,
    list: [],
  },
  changeTab(event) {
    let active = event.currentTarget.dataset.current;
    this.setData({
      active,
    });
  },
  changeZb(event) {
    let zb = event.currentTarget.dataset.zb;
    this.setData({
      zb,
    });
  },
  openItem(event) {
    let index = event.currentTarget.dataset.index;
    let list = JSON.parse(JSON.stringify(this.data.list));
    list[index].isOpen = !list[index].isOpen;
    this.setData({
      list
    });
  },
  // 上下拉加载
  // 触底
  scrolltolower() {
    if (!this.data.hasMore) {
      return ;
    }
    let page = this.data.page + 1;
    this.setData({
      page,
    })
    this.getList()
  },
  // 下拉刷新
  handleRefresherRefresh() {
		this.setData({
			refresherStatus: true,
			page: 1,
      hasMore: true,
		})
		this.getList()
	},
  getList() {
    mineApi.getProjectList({
      page: this.data.page,
      page_size: this.data.page_size
    }).then((res) => {
      let arr = res.data.list.map(item => {
        item.isOpen = true
        return item
      })
      this.setData({
        list: this.data.page == 1 ? arr : this.data.list.concat(arr),
        total: res.data.total,
        refresherStatus: false,
        hasMore: this.data.page * this.data.page_size <= res.data.total,
      })
    })
  },
  onLoad(options) {
   this.getList()
  },
  onReady() {},
  onShow() {},
  onHide() {},
  onUnload() {},
  onShareAppMessage() {
    return {
      title: "",
    };
  },
});
